package service.cfg;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.context.ContextLoader;

import javax.servlet.ServletContext;

/**
 * Created by asus on 2018/10/18.
 */
@Service
public class ImageCfg {

    @Value("#{config['image.path']}")
    private String path;


    public String getPath() {
        if (StringUtils.isBlank(this.path)) {
            synchronized (this) {
                if (StringUtils.isBlank(this.path)) {
                    ServletContext servletContext = ContextLoader.getCurrentWebApplicationContext().getServletContext();
                    this.path = servletContext.getRealPath("/") + "/upload";
                }
            }
        }
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }
}
